package com.ts.api.module.match.plan.internal.distribute.context;

import com.ts.api.module.match.core.MatchRegisterContext;
import com.ts.api.module.match.plan.internal.distribute.strategy.ApiOrgPhoneMaskDistribute;
import com.ts.api.module.match.plan.internal.distribute.strategy.ApiOrgPhoneMd5Distribute;
import com.ts.api.module.match.plan.internal.distribute.strategy.ApiPlatformPhoneMaskDistribute;
import com.ts.api.module.match.plan.internal.distribute.strategy.ApiPlatformPhoneMd5Distribute;
import com.ts.api.module.match.plan.internal.distribute.strategy.ApiSpecialPhoneMaskDistribute;
import com.ts.api.module.match.plan.internal.distribute.strategy.ApiSpecialPhoneMd5Distribute;
import com.ts.api.module.match.plan.internal.distribute.strategy.LocalOrgDistribute;
import com.ts.api.module.match.plan.internal.distribute.strategy.LocalSpecialDistribute;
import com.ts.api.module.match.plan.internal.distribute.strategy.PlanDistributeStrategy;
import com.ts.api.module.product.entity.po.ProductPO;
import com.ts.api.module.product.entity.po.ProductPlanPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *  API渠道-计划分发上下文
 *
 *  @author Pan
 */
@Component
public class ApiPlanDistributeContext extends MatchRegisterContext<PlanDistributeType, PlanDistributeStrategy> {

    @Autowired
    private PlanDistributeContext planDistributeContext;

    public ApiPlanDistributeContext() {
        super(PlanDistributeType.class);
        register(PlanDistributeType.LOCAL_ORG, LocalOrgDistribute.class);
        register(PlanDistributeType.API_ORG_PHONE_MD5, ApiOrgPhoneMd5Distribute.class);
        register(PlanDistributeType.API_ORG_PHONE_MASK, ApiOrgPhoneMaskDistribute.class);

        register(PlanDistributeType.API_PLAT_FORM_PHONE_MD5, ApiPlatformPhoneMd5Distribute.class);
        register(PlanDistributeType.API_PLAT_FORM_PHONE_MASK, ApiPlatformPhoneMaskDistribute.class);

        register(PlanDistributeType.LOCAL_SPECIAL, LocalSpecialDistribute.class);
        register(PlanDistributeType.API_SPECIAL_PHONE_MD5, ApiSpecialPhoneMd5Distribute.class);
        register(PlanDistributeType.API_SPECIAL_PHONE_MASK, ApiSpecialPhoneMaskDistribute.class);
    }

    /**
     *  获取分发上下文
     *
     *  @param  productPO       主体信息
     *  @param  productPlanPO   计划信息
     *  @return PlanDistributeStrategy
     */
    public PlanDistributeStrategy getContext(ProductPO productPO, ProductPlanPO productPlanPO) {
        PlanDistributeType distributeType = planDistributeContext.getDistributeType(productPO, productPlanPO);
        PlanDistributeStrategy strategy = super.getContext(distributeType);
        if (strategy == null) {
            throw new IllegalArgumentException("distribute strategy not exist");
        }
        return strategy;
    }
}
